import request from '@/router/axios';

/**
 * 字典类型树
 */
export const configTree = () => {
  return request({
    url: '/system/config/configTree',
    method: 'get'
  })
}

/**
 * 字典项列表
 * @param current
 * @param size
 * @param params
 */
export const getList = (current, size, params) => {
  return request({
    url: '/system/dict/page',
    method: 'POST',
    params: {
      ...params,
      current,
      size,
    }
  })
}

//字典类别唯一性校验
export const verifyConfigUnique = (data) => request({
  url: '/system/config/verifyUnique',
  method: 'post',
  params: data
})

/**
 * 新增字典类别
 * @param row
 */
export const addConfig = (row) => {
  return request({
    url: '/system/config/add',
    method: 'post',
    data: row
  })
}

/**
 * 根据ID获取字典类别信息
 * @param configId
 */
export const editConfig = (configId) => {
  return request({
    url: '/system/config/edit/' + configId,
    method: 'get'
  })
}

/**
 * 更新字典类别
 * @param row
 */
export const updateConfig = (row) => {
  return request({
    url: '/system/config/update',
    method: 'post',
    data: row
  })
}

/**
 * 删除字典类别
 * @param configId
 */
export const removeConfig = (configId) => {
  return request({
    url: '/system/config/remove',
    method: 'post',
    params: {configId}
  })
}

//字典项唯一性校验
export const verifyUnique = (data) => request({
  url: '/system/dict/verifyUnique',
  method: 'post',
  params: data
})

/**
 * 新增字典项
 * @param row
 */
export const add = (row) => {
  return request({
    url: '/system/dict/add',
    method: 'post',
    data: row
  })
}

/**
 * 字典项树
 * @param configId
 */
export const dictTree = (configId) => {
  return request({
    url: '/system/dict/dictTree/' + configId,
    method: 'get'
  })
}

/**
 * 更新字典项
 * @param row
 */
export const update = (row) => {
  return request({
    url: '/system/dict/update',
    method: 'post',
    data: row
  })
}

/**
 * 删除字典项
 * @param row
 */
export const remove = (row) => {
  return request({
    url: '/system/dict/remove',
    method: 'post',
    data: row
  })
}

/**
 * 获取字典项
 * @param configCode
 */
export const dictTreeByCode = (configCode) => {
  return request({
    url: '/system/dict/dictTreeByCode/' + configCode,
    method: 'get'
  })
}